package cyy.example.com.facotry.constants;

import com.example.com.common.utils.constants.GetJsonDataUtil;
import com.google.gson.Gson;

import java.util.List;

import cyy.example.com.facotry.Factory;
import cyy.example.com.facotry.model.api.response.BaseUrlEntity;
import cyy.example.com.facotry.net.Network;

/**
 * Created by ChenYiYao on 2018/4/17.
 */

public class ControlEvnUtils {
    public final static void Refresh(int i) {
        CommonConstants.ENV_TYPE = i;
        changeBaseUrl();
    }

    private final static void changeBaseUrl() {
        switch (CommonConstants.ENV_TYPE) {
            case CommonConstants.ENV_DEV://内网环境
                CommonConstants.API_URL_PREFIX = CommonConstants.Constance.API_URL;
//                CommonConstants.FILE_URL_PREFIX_WEB = CommonConstants.Constance.FILE_URL_WEB;
//                L.isDebug = true;
                break;
            case CommonConstants.ENV_PRO://外网环境
                CommonConstants.API_URL_PREFIX = CommonConstants.Constance.FORMAL_API_URL;
//                CommonConstants.FILE_URL_PREFIX_WEB = CommonConstants.Constance.FORMAL_FILE_URL_WEB;
//                L.isDebug = false;
                break;
        }
        Network.restRetrofit();
    }

    public static void alterUrl(String baseUrl, String fileUrl, String fileURlWeb) {
        changeBaseUrl(baseUrl, fileUrl, fileURlWeb);
    }

    public static List<BaseUrlEntity.BodyBean.BaseUrlBean> getURlEntity() {
        Gson g = new Gson();
        String JsonData = new GetJsonDataUtil().getJson(Factory.app(), "BaseUrl.json");//获取assets目录下的json文件数据
        BaseUrlEntity baseUrlEntity = g.fromJson(JsonData, BaseUrlEntity.class);
        List<BaseUrlEntity.BodyBean.BaseUrlBean> baseUrl = baseUrlEntity.getBody().getBaseUrl();
        return baseUrl;
    }

    private final static void changeBaseUrl(String baseUrl, String fileUrl, String fileURlWeb) {
        CommonConstants.API_URL_PREFIX = baseUrl;
//        CommonConstants.FILE_URL_PREFIX_WEB = fileURlWeb;
        Network.restRetrofit();
    }
}
